// code_modules.h: Contains all of the CodeModule objects that were loaded
// into a single process.
//

#ifndef LONGKEY_BREAKPAD_PROCESSOR_CODE_MODULES_H_
#define LONGKEY_BREAKPAD_PROCESSOR_CODE_MODULES_H_

namespace longkey_breakpad
{
	class CodeModule;

	class CodeModules
	{
	public:
		virtual ~CodeModules();

		// The number of contained CodeModule objects.
		virtual unsigned int module_count() const = 0;

		// Random access to modules.  Returns the module whose code is present
		// at the address indicated by |address|.  If no module is present at this
		// address, returns NULL.  Ownership of the returned CodeModule is retained
		// by the CodeModules object; pointers returned by this method are valid for
		// comparison with pointers returned by the other Get methods.
		virtual const CodeModule* GetModuleForAddress(u_int64_t address) const = 0;

		// Returns the module corresponding to the main executable.  If there is
		// no main executable, returns NULL.  Ownership of the returned CodeModule
		// is retained by the CodeModules object; pointers returned by this method
		// are valid for comparison with pointers returned by the other Get
		// methods.
		virtual const CodeModule* GetMainModule() const = 0;

		// Sequential access to modules.  A sequence number of 0 corresponds to the
		// module residing lowest in memory.  If the sequence number is out of
		// range, returns NULL.  Ownership of the returned CodeModule is retained
		// by the CodeModules object; pointers returned by this method are valid for
		// comparison with pointers returned by the other Get methods.
		virtual const CodeModule* GetModuleAtSequence(
			unsigned int sequence) const = 0;

		// Sequential access to modules.  This is similar to GetModuleAtSequence,
		// except no ordering requirement is enforced.  A CodeModules implementation
		// may return CodeModule objects from GetModuleAtIndex in any order it
		// wishes, provided that the order remain the same throughout the life of
		// the CodeModules object.  Typically, GetModuleAtIndex would be used by
		// a caller to enumerate all CodeModule objects quickly when the enumeration
		// does not require any ordering.  If the index argument is out of range,
		// returns NULL.  Ownership of the returned CodeModule is retained by
		// the CodeModules object; pointers returned by this method are valid for
		// comparison with pointers returned by the other Get methods.
		virtual const CodeModule* GetModuleAtIndex(unsigned int index) const = 0;

		// Creates a new copy of this CodeModules object, which the caller takes
		// ownership of.  The new object will also contain copies of the existing
		// object's child CodeModule objects.  The new CodeModules object may be of
		// a different concrete class than the object being copied, but will behave
		// identically to the copied object as far as the CodeModules and CodeModule
		// interfaces are concerned, except that the order that GetModuleAtIndex
		// returns objects in may differ between a copy and the original CodeModules
		// object.
		virtual const CodeModules* Copy() const = 0;
	};
}

#endif